package com.y.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.commons.lang3.StringUtils;

public class CopyrightDelete {
	public static void main(String[] args) throws IOException {
		String rootPath = "D:/GIT/SpringBlade/src";
		File parentFile = new File(rootPath);
		handleFile(parentFile);
	}

	public static void handleFile(File f) throws IOException {
		if (f.isDirectory()) {
			for (File file : f.listFiles()) {
				handleFile(file);
			}
		} else {
			// 处理文件
			StringBuilder content = new StringBuilder();
			if (f.getName().endsWith(".java")) {
				try  {
					BufferedReader br = new BufferedReader(new FileReader(f));
					String line = null;
					int count = 0;
					boolean isSkip15Line=false;
					while ((line = br.readLine()) != null) {
						if(count==0){
							//如果为/**开头则为无效数据,过滤15行
							if(line.startsWith("/**")){
								System.err.println(String.format("需要处理为的文件:%s", f));
								isSkip15Line=true;
							}
						}else{
							if(isSkip15Line){
								if(count>=15){
									if (StringUtils.isNotBlank(line)) {
										content.append(line);
										content.append("\n");
									}
								}
							}
						}
						count++;
					}
					br.close();
					if (isSkip15Line) {
						System.out.println(content.toString());
						//写入文件
						FileWriter fw=new FileWriter(f);
						fw.write(content.toString());
						fw.close();
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
}
